<?php

namespace Home\Controller;
use Home\Controller\BaseController;

class HomeController extends BaseController {

    public $loginUrl;

    public function _initialize() {
        parent::_initialize();

        $forward = getUrl();
        $loginUrl = USERS_URL . '/Login/index?forward=' . $forward;
        $this->loginUrl = $loginUrl;
        $this->assign('forward', $forward);
        $this->assign('loginUrl', $loginUrl);

        //未登录调转至登录页
        if(!session('user_id')){
            //记录跳转至登陆页面前的地址
            session("forward",$forward);
            $this->redirect('Login/index');
        }
        
        $all = M('Order')->where(array('user_id'=>session('user_id')))->count();
        $waitPay = M('Order')->where(array('user_id'=>session('user_id'),'order_state'=>10))->count();
        $waitSend = M('Order')->where(array('user_id'=>session('user_id'),'order_state'=>20))->count();
        $waitConfirm = M('Order')->where(array('user_id'=>session('user_id'),'order_state'=>30))->count();
        $waitRate = M('Order')->where(array('user_id'=>session('user_id'),'order_state'=>40))->count();
        $this->assign("all", $all);
        $this->assign("waitPay", $waitPay);
        $this->assign("waitSend", $waitSend);
        $this->assign("waitConfirm", $waitConfirm);
        $this->assign("waitRate", $waitRate);

    }


    
}
